<?xml version="1.0" encoding="UTF-8"?>
<!-- ======================================================== -->
<!-- Posterita Web POS Application                           -->
<!-- ======================================================== -->

<project name="posterita" default="dist" basedir=".">

	<property environment="env" />
	<property file="build.properties" />

	<property name="src.dir" value="${basedir}/src" />
	<property name="src.main.dir" value="${src.dir}/main" />
	<property name="src.aspect.dir" value="${src.dir}/aspect" />
	<property name="src.web.dir" value="${basedir}/web" />
	<property name="build.dir" value="${basedir}/build" />
	<property name="dist.dir" value="${basedir}/dist/" />
	<property name="dist.lib.dir" value="${dist.dir}/lib" />
	<property name="build.deploy.dir" value="${build.dir}/deploy" />
	<property name="work.dir" value="${basedir}/work" />
	<property name="utils.dir" value="${src.dir}/utils" />
	<!--property name="reference.adempiere.dir" value="../reference/Adempiere340" /-->
	<property name="reference.adempiere.dir" value="../../tools" />
	<property name="reference.adempiere.lib" value="../../lib" />
	<property name="reference.aspectj.dir" value="../reference/aspectJ" />
	<property name="posteritadevhome.exists" value="false" />
	<property file="${posterita.dev.home}/AdempiereEnv.properties" />
	
  	<taskdef resource="org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties">
	    <classpath>
    		<pathelement location="${reference.aspectj.dir}/aspectjtools.jar"/>
    	</classpath>
  	</taskdef>

	<target name="init">
		<echo message="=========== Build Posterita POS ===========" />
		<tstamp />
		<mkdir dir="${build.dir}" />
		<mkdir dir="${dist.dir}" />
		<mkdir dir="${dist.lib.dir}" />

		<!-- Delete old posterita.jar -->
		<delete file="${src.web.dir}/WEB-INF/lib/posterita.jar" failonerror="false" />

	</target>

	<!-- Creating new posterita.jar -->
	<target name="compile" depends="init">
		<!-- compile the java code from ${src} into ${build.dir} -->
		<javac srcdir="${src.main.dir}" destdir="${src.web.dir}/WEB-INF/classes" deprecation="on" source="1.5" target="1.5" debug="on">
			<classpath>
				<fileset dir="${src.web.dir}/WEB-INF/lib/">
					<include name="*.jar" />
				</fileset>
				<fileset dir="${reference.adempiere.dir}/lib/">
					<include name="*.jar" />
				</fileset>
				<fileset dir="${reference.adempiere.lib}">
					<include name="CCTools.jar"/>
					<include name="adempiereApps.jar"/>
					<include name="CSTools.jar"/>
					<include name="Adempiere.jar"/>
					<include name="CompiereJasperReqs.jar"/>
				</fileset>
			</classpath>
		</javac>
		<jar destfile="${dist.dir}/lib/posterita.jar" basedir="${build.dir}">
			<include name="org/**"/>
		</jar>
		<jar destfile="${dist.dir}/lib/posteritaPatches.jar" basedir="${build.dir}">
			<include name="org/compiere/**"/>
		</jar>
	</target>
	
	<target name="createAspectJar" depends="compile">
		<iajc srcdir="${src.aspect.dir}" destdir="${build.dir}" deprecation="on" source="1.5" target="1.5" debug="on" outxml="true" outxmlfile="META-INF/aop.xml">
			<classpath>
				<fileset dir="${dist.dir}/lib/">
					<include name="*.jar" />
				</fileset>
				<fileset dir="${src.web.dir}/WEB-INF/lib/">
					<include name="*.jar" />
				</fileset>
				<fileset dir="${reference.adempiere.dir}/lib/">
					<include name="*.jar" />
				</fileset>
			</classpath>
		</iajc>
		<jar destfile="${src.web.dir}/WEB-INF/lib/aop.jar" basedir="${build.dir}">
			<include name="org/posterita/aspect/**" />
			<include name="META-INF/**"/>
		</jar>	
	</target>

	<!-- =================================================================== -->
	<!-- Creates the war archives                                            -->
	<!-- =================================================================== -->
	<target name="war" depends="compile">
		<war warfile="${dist.dir}/lib/posterita.war" webxml="${src.web.dir}/WEB-INF/web.xml">
			<fileset dir="${src.web.dir}" excludes="**/web.xml,**/classes/org/compiere/**" />
			<fileset dir="${src.web.dir}" includes="**/classes/*.properties" />
			<manifest>
				<attribute name="Specification-Title" value="Posterita POS" />
				<attribute name="Specification-Version" value="${env.ADEMPIERE_VERSION}" />
				<attribute name="Specification-Vendor" value="Adempiere, Inc." />
				<attribute name="Implementation-Title" value="Posterita POS ${env.ADEMPIERE_VERSION}" />
				<attribute name="Implementation-Version" value="${env.ADEMPIERE_VERSION} ${DSTAMP}-${TSTAMP}" />
				<attribute name="Implementation-Vendor" value="${env.ADEMPIERE_VENDOR}" />
				<attribute name="Implementation-URL" value="http://www.posterita.org" />
				<attribute name="Class-Path" value="Adempiere.jar AdempiereSLib.jar adempiereApps.jar posterita.jar" />
			</manifest>
		</war>

	</target>

	<!-- =================================================================== -->
	<!-- Creates Distributables                                              -->
	<!-- =================================================================== -->
	<target name="dist" depends="war">
		<copy todir="../../lib">
			<fileset dir="${dist.lib.dir}"/>
		</copy>
	</target>

	<target name="jar" depends="war">
	</target>

	<!-- =================================================================== -->
	<!-- Cleans up the current build                                         -->
	<!-- =================================================================== -->
	<target name="clean">
		<delete dir="${build.dir}" />
		<delete dir="${dist.dir}" />
		<delete dir="${work.dir}" />

	</target>

	<available type="dir" file="${posterita.dev.home}/jboss/server/adempiere/deploy/adempiere.ear" property="${posteritadevhome.exists}" />
	
	<!-- Sign Posterita Jar -->
	<!-- printOrderApplet.jar -->
	<target name="signPrintApplet">
		<fail unless="${posteritadevhome.exists}" message="Posterita Development home not set correctly in build.properties" />
		
		<signjar jar="${src.web.dir}/applets/printOrderApplet.jar" alias="${ADEMPIERE_KEYSTORECODEALIAS}" 
			storepass="${ADEMPIERE_KEYSTOREPASS}" keystore="${ADEMPIERE_KEYSTORE}" />
	</target>
		
	<target name="explode">
		<fail unless="${posteritadevhome.exists}" message="Posterita Development home not set correctly in build.properties" />
		<copy todir="${posterita.dev.home}/jboss/server/adempiere/deploy/adempiere.ear/posterita.war">
			<fileset dir="${basedir}/web" includes="**/*.*" />
		</copy>
	</target>

	<target name="unexplode">
		<fail unless="${posteritadevhome.exists}" message="Posterita Development home not set correctly in build.properties" />
		<delete dir="${posterita.dev.home}/jboss/server/adempiere/deploy/adempiere.ear/posterita.war" />
	</target>

</project>
